
<!DOCTYPE HTML>
<html lang="zh-hans" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>Writing is nice · react源码详细解读</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="gugu">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchors/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-donate/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-anchor-navigation-ex/style/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    

        
    
    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="gitbook.html" />
    
    
    <link rel="prev" href="../" />
    

    
        <link rel="shortcut icon" href='../source/images/favicon.jpg' type="image/x-icon">
    
    
        <link rel="bookmark" href='../source/images/favicon.jpg' type="image/x-icon">
    
    
        <link rel="apple-touch-icon" href='../source/images/apple-touch-icon.jpg'>
    
    
        
        <link rel="apple-touch-icon" sizes="120x120" href="../source/images/apple-touch-icon.jpg">
        
        <link rel="apple-touch-icon" sizes="180x180" href="../source/images/apple-touch-icon.jpg">
        
    

    <style>
    @media only screen and (max-width: 640px) {
        .book-header .hidden-mobile {
            display: none;
        }
    }
    </style>
    <script>
        window["gitbook-plugin-github-buttons"] = {"buttons":[{"user":"Blankj","repo":"glory","type":"star","size":"small","count":true}]};
    </script>

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://blankj.com" target="_blank" class="custom-link">我的狗窝</a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        <li class="header">准备工作</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.2" data-path="writing.html">
            
                <a href="writing.html">
            
                    
                    Writing is nice
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="gitbook.html">
            
                <a href="gitbook.html">
            
                    
                    GitBook is nice
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">Part II</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../part2/feedback_please.html">
            
                <a href="../part2/feedback_please.html">
            
                    
                    Introduction
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../part2/better_tools.html">
            
                <a href="../part2/better_tools.html">
            
                    
                    Better tools for authors
            
                </a>
            

            
        </li>
    

    
        
        <li class="divider"></li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../part3/title.md">
            
                <span>
            
                    
                    Last part without title
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >Writing is nice</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <div id="anchor-navigation-ex-navbar"><i class="fa fa-navicon"></i><ul><li><span class="title-icon "></span><a href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><b></b>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;</a></li><ul><li><span class="title-icon "></span><a href="#&#x666E;&#x901A;&#x51FD;&#x6570;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><b></b>&#x666E;&#x901A;&#x51FD;&#x6570;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#promise-&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><b></b>Promise &#x5F02;&#x6B65;&#x7EC4;&#x4EF6;</a></li><li><span class="title-icon "></span><a href="#&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><b></b>&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;</a></li><ul><li><span class="title-icon "></span><a href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x5931;&#x8D25;"><b></b>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x5931;&#x8D25;</a></li><li><span class="title-icon "></span><a href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;"><b></b>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;</a></li><li><span class="title-icon "></span><a href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x4E2D;"><b></b>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x4E2D;</a></li><li><span class="title-icon "></span><a href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x8D85;&#x65F6;"><b></b>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x8D85;&#x65F6;</a></li></ul><li><span class="title-icon "></span><a href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;-patch"><b></b>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6; patch</a></li><li><span class="title-icon "></span><a href="#&#x603B;&#x7ED3;"><b></b>&#x603B;&#x7ED3;</a></li></ul></ul></div><a href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;" id="anchorNavigationExGoTop"><i class="fa fa-arrow-up"></i></a><h1 id="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;" class="plugin-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;</h1>
<p>&#x5728;&#x6211;&#x4EEC;&#x5E73;&#x65F6;&#x7684;&#x5F00;&#x53D1;&#x5DE5;&#x4F5C;&#x4E2D;&#xFF0C;&#x4E3A;&#x4E86;&#x51CF;&#x5C11;&#x9996;&#x5C4F;&#x4EE3;&#x7801;&#x4F53;&#x79EF;&#xFF0C;&#x5F80;&#x5F80;&#x4F1A;&#x628A;&#x4E00;&#x4E9B;&#x975E;&#x9996;&#x5C4F;&#x7684;&#x7EC4;&#x4EF6;&#x8BBE;&#x8BA1;&#x6210;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#xFF0C;&#x6309;&#x9700;&#x52A0;&#x8F7D;&#x3002;Vue &#x4E5F;&#x539F;&#x751F;&#x652F;&#x6301;&#x4E86;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7684;&#x80FD;&#x529B;&#xFF0C;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js">Vue.component(<span class="hljs-string">&apos;async-example&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params">resolve, reject</span>) </span>{
   <span class="hljs-comment">// &#x8FD9;&#x4E2A;&#x7279;&#x6B8A;&#x7684; require &#x8BED;&#x6CD5;&#x544A;&#x8BC9; webpack</span>
   <span class="hljs-comment">// &#x81EA;&#x52A8;&#x5C06;&#x7F16;&#x8BD1;&#x540E;&#x7684;&#x4EE3;&#x7801;&#x5206;&#x5272;&#x6210;&#x4E0D;&#x540C;&#x7684;&#x5757;&#xFF0C;</span>
   <span class="hljs-comment">// &#x8FD9;&#x4E9B;&#x5757;&#x5C06;&#x901A;&#x8FC7; Ajax &#x8BF7;&#x6C42;&#x81EA;&#x52A8;&#x4E0B;&#x8F7D;&#x3002;</span>
   <span class="hljs-built_in">require</span>([<span class="hljs-string">&apos;./my-async-component&apos;</span>], resolve)
})
</code></pre>
<p>&#x793A;&#x4F8B;&#x4E2D;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#xFF0C;Vue &#x6CE8;&#x518C;&#x7684;&#x7EC4;&#x4EF6;&#x4E0D;&#x518D;&#x662F;&#x4E00;&#x4E2A;&#x5BF9;&#x8C61;&#xFF0C;&#x800C;&#x662F;&#x4E00;&#x4E2A;&#x5DE5;&#x5382;&#x51FD;&#x6570;&#xFF0C;&#x51FD;&#x6570;&#x6709;&#x4E24;&#x4E2A;&#x53C2;&#x6570; <code>resolve</code> &#x548C; <code>reject</code>&#xFF0C;&#x51FD;&#x6570;&#x5185;&#x90E8;&#x7528; <code>setTimout</code> &#x6A21;&#x62DF;&#x4E86;&#x5F02;&#x6B65;&#xFF0C;&#x5B9E;&#x9645;&#x4F7F;&#x7528;&#x53EF;&#x80FD;&#x662F;&#x901A;&#x8FC7;&#x52A8;&#x6001;&#x8BF7;&#x6C42;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7684; JS &#x5730;&#x5740;&#xFF0C;&#x6700;&#x7EC8;&#x901A;&#x8FC7;&#x6267;&#x884C; <code>resolve</code> &#x65B9;&#x6CD5;&#xFF0C;&#x5B83;&#x7684;&#x53C2;&#x6570;&#x5C31;&#x662F;&#x6211;&#x4EEC;&#x7684;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x5BF9;&#x8C61;&#x3002;</p>
<p>&#x5728;&#x4E86;&#x89E3;&#x4E86;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x5982;&#x4F55;&#x6CE8;&#x518C;&#x540E;&#xFF0C;&#x6211;&#x4EEC;&#x4ECE;&#x6E90;&#x7801;&#x7684;&#x89D2;&#x5EA6;&#x6765;&#x5206;&#x6790;&#x4E00;&#x4E0B;&#x5B83;&#x7684;&#x5B9E;&#x73B0;&#x3002;</p>
<p>&#x4E0A;&#x4E00;&#x8282;&#x6211;&#x4EEC;&#x5206;&#x6790;&#x4E86;&#x7EC4;&#x4EF6;&#x7684;&#x6CE8;&#x518C;&#x903B;&#x8F91;&#xFF0C;&#x7531;&#x4E8E;&#x7EC4;&#x4EF6;&#x7684;&#x5B9A;&#x4E49;&#x5E76;&#x4E0D;&#x662F;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x5BF9;&#x8C61;&#xFF0C;&#x6240;&#x4EE5;&#x4E0D;&#x4F1A;&#x6267;&#x884C; <code>Vue.extend</code> &#x7684;&#x903B;&#x8F91;&#x628A;&#x5B83;&#x53D8;&#x6210;&#x4E00;&#x4E2A;&#x7EC4;&#x4EF6;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#xFF0C;&#x4F46;&#x662F;&#x5B83;&#x4ECD;&#x7136;&#x53EF;&#x4EE5;&#x6267;&#x884C;&#x5230; <code>createComponent</code> &#x51FD;&#x6570;&#xFF0C;&#x6211;&#x4EEC;&#x518D;&#x6765;&#x5BF9;&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x505A;&#x56DE;&#x987E;&#xFF0C;&#x5B83;&#x7684;&#x5B9A;&#x4E49;&#x5728; <code>src/core/vdom/create-component/js</code> &#x4E2D;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createComponent</span> (<span class="hljs-params">
  Ctor: Class&lt;Component&gt; | Function | Object | void,
  data: ?VNodeData,
  context: Component,
  children: ?Array&lt;VNode&gt;,
  tag?: string
</span>): <span class="hljs-title">VNode</span> | <span class="hljs-title">Array</span>&lt;<span class="hljs-title">VNode</span>&gt; | <span class="hljs-title">void</span> </span>{
  <span class="hljs-keyword">if</span> (isUndef(Ctor)) {
    <span class="hljs-keyword">return</span>
  }

  <span class="hljs-keyword">const</span> baseCtor = context.$options._base

  <span class="hljs-comment">// plain options object: turn it into a constructor</span>
  <span class="hljs-keyword">if</span> (isObject(Ctor)) {
    Ctor = baseCtor.extend(Ctor)
  }

  <span class="hljs-comment">// ...</span>

  <span class="hljs-comment">// async component</span>
  <span class="hljs-keyword">let</span> asyncFactory
  <span class="hljs-keyword">if</span> (isUndef(Ctor.cid)) {
    asyncFactory = Ctor
    Ctor = resolveAsyncComponent(asyncFactory, baseCtor, context)
    <span class="hljs-keyword">if</span> (Ctor === <span class="hljs-literal">undefined</span>) {
      <span class="hljs-comment">// return a placeholder node for async component, which is rendered</span>
      <span class="hljs-comment">// as a comment node but preserves all the raw information for the node.</span>
      <span class="hljs-comment">// the information will be used for async server-rendering and hydration.</span>
      <span class="hljs-keyword">return</span> createAsyncPlaceholder(
        asyncFactory,
        data,
        context,
        children,
        tag
      )
    }
  }
}
</code></pre>
<p>&#x6211;&#x4EEC;&#x7701;&#x7565;&#x4E86;&#x4E0D;&#x5FC5;&#x8981;&#x7684;&#x903B;&#x8F91;&#xFF0C;&#x53EA;&#x4FDD;&#x7559;&#x5173;&#x952E;&#x903B;&#x8F91;&#xFF0C;&#x7531;&#x4E8E;&#x6211;&#x4EEC;&#x8FD9;&#x4E2A;&#x65F6;&#x5019;&#x4F20;&#x5165;&#x7684; <code>Ctor</code> &#x662F;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x90A3;&#x4E48;&#x5B83;&#x4E5F;&#x5E76;&#x4E0D;&#x4F1A;&#x6267;&#x884C; <code>Vue.extend</code> &#x903B;&#x8F91;&#xFF0C;&#x56E0;&#x6B64;&#x5B83;&#x7684; <code>cid</code> &#x662F; <code>undefiend</code>&#xFF0C;&#x8FDB;&#x5165;&#x4E86;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x521B;&#x5EFA;&#x7684;&#x903B;&#x8F91;&#x3002;&#x8FD9;&#x91CC;&#x9996;&#x5148;&#x6267;&#x884C;&#x4E86; <code>Ctor = resolveAsyncComponent(asyncFactory, baseCtor, context)</code> &#x65B9;&#x6CD5;&#xFF0C;&#x5B83;&#x7684;&#x5B9A;&#x4E49;&#x5728; <code>src/core/vdom/helpers/resolve-async-component.js</code> &#x4E2D;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">resolveAsyncComponent</span> (<span class="hljs-params">
  factory: Function,
  baseCtor: Class&lt;Component&gt;,
  context: Component
</span>): <span class="hljs-title">Class</span>&lt;<span class="hljs-title">Component</span>&gt; | <span class="hljs-title">void</span> </span>{
  <span class="hljs-keyword">if</span> (isTrue(factory.error) &amp;&amp; isDef(factory.errorComp)) {
    <span class="hljs-keyword">return</span> factory.errorComp
  }

  <span class="hljs-keyword">if</span> (isDef(factory.resolved)) {
    <span class="hljs-keyword">return</span> factory.resolved
  }

  <span class="hljs-keyword">if</span> (isTrue(factory.loading) &amp;&amp; isDef(factory.loadingComp)) {
    <span class="hljs-keyword">return</span> factory.loadingComp
  }

  <span class="hljs-keyword">if</span> (isDef(factory.contexts)) {
    <span class="hljs-comment">// already pending</span>
    factory.contexts.push(context)
  } <span class="hljs-keyword">else</span> {
    <span class="hljs-keyword">const</span> contexts = factory.contexts = [context]
    <span class="hljs-keyword">let</span> sync = <span class="hljs-literal">true</span>

    <span class="hljs-keyword">const</span> forceRender = () =&gt; {
      <span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>, l = contexts.length; i &lt; l; i++) {
        contexts[i].$forceUpdate()
      }
    }

    <span class="hljs-keyword">const</span> resolve = once((res: <span class="hljs-built_in">Object</span> | Class&lt;Component&gt;) =&gt; {
      <span class="hljs-comment">// cache resolved</span>
      factory.resolved = ensureCtor(res, baseCtor)
      <span class="hljs-comment">// invoke callbacks only if this is not a synchronous resolve</span>
      <span class="hljs-comment">// (async resolves are shimmed as synchronous during SSR)</span>
      <span class="hljs-keyword">if</span> (!sync) {
        forceRender()
      }
    })

    <span class="hljs-keyword">const</span> reject = once(reason =&gt; {
      process.env.NODE_ENV !== <span class="hljs-string">&apos;production&apos;</span> &amp;&amp; warn(
        <span class="hljs-string">`Failed to resolve async component: <span class="hljs-subst">${String(factory)}</span>`</span> +
        (reason ? <span class="hljs-string">`\nReason: <span class="hljs-subst">${reason}</span>`</span> : <span class="hljs-string">&apos;&apos;</span>)
      )
      <span class="hljs-keyword">if</span> (isDef(factory.errorComp)) {
        factory.error = <span class="hljs-literal">true</span>
        forceRender()
      }
    })

    <span class="hljs-keyword">const</span> res = factory(resolve, reject)

    <span class="hljs-keyword">if</span> (isObject(res)) {
      <span class="hljs-keyword">if</span> (<span class="hljs-keyword">typeof</span> res.then === <span class="hljs-string">&apos;function&apos;</span>) {
        <span class="hljs-comment">// () =&gt; Promise</span>
        <span class="hljs-keyword">if</span> (isUndef(factory.resolved)) {
          res.then(resolve, reject)
        }
      } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (isDef(res.component) &amp;&amp; <span class="hljs-keyword">typeof</span> res.component.then === <span class="hljs-string">&apos;function&apos;</span>) {
        res.component.then(resolve, reject)

        <span class="hljs-keyword">if</span> (isDef(res.error)) {
          factory.errorComp = ensureCtor(res.error, baseCtor)
        }

        <span class="hljs-keyword">if</span> (isDef(res.loading)) {
          factory.loadingComp = ensureCtor(res.loading, baseCtor)
          <span class="hljs-keyword">if</span> (res.delay === <span class="hljs-number">0</span>) {
            factory.loading = <span class="hljs-literal">true</span>
          } <span class="hljs-keyword">else</span> {
            setTimeout(() =&gt; {
              <span class="hljs-keyword">if</span> (isUndef(factory.resolved) &amp;&amp; isUndef(factory.error)) {
                factory.loading = <span class="hljs-literal">true</span>
                forceRender()
              }
            }, res.delay || <span class="hljs-number">200</span>)
          }
        }

        <span class="hljs-keyword">if</span> (isDef(res.timeout)) {
          setTimeout(() =&gt; {
            <span class="hljs-keyword">if</span> (isUndef(factory.resolved)) {
              reject(
                process.env.NODE_ENV !== <span class="hljs-string">&apos;production&apos;</span>
                  ? <span class="hljs-string">`timeout (<span class="hljs-subst">${res.timeout}</span>ms)`</span>
                  : <span class="hljs-literal">null</span>
              )
            }
          }, res.timeout)
        }
      }
    }

    sync = <span class="hljs-literal">false</span>
    <span class="hljs-comment">// return in case resolved synchronously</span>
    <span class="hljs-keyword">return</span> factory.loading
      ? factory.loadingComp
      : factory.resolved
  }
}
</code></pre>
<p><code>resolveAsyncComponent</code> &#x51FD;&#x6570;&#x7684;&#x903B;&#x8F91;&#x7565;&#x590D;&#x6742;&#xFF0C;&#x56E0;&#x4E3A;&#x5B83;&#x5B9E;&#x9645;&#x4E0A;&#x5904;&#x7406;&#x4E86; 3 &#x79CD;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7684;&#x521B;&#x5EFA;&#x65B9;&#x5F0F;&#xFF0C;&#x9664;&#x4E86;&#x521A;&#x624D;&#x793A;&#x4F8B;&#x7684;&#x7EC4;&#x4EF6;&#x6CE8;&#x518C;&#x65B9;&#x5F0F;&#xFF0C;&#x8FD8;&#x652F;&#x6301; 2 &#x79CD;&#xFF0C;&#x4E00;&#x79CD;&#x662F;&#x652F;&#x6301; <code>Promise</code> &#x521B;&#x5EFA;&#x7EC4;&#x4EF6;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js">Vue.component(
  <span class="hljs-string">&apos;async-webpack-example&apos;</span>,
  <span class="hljs-comment">// &#x8BE5; `import` &#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A; `Promise` &#x5BF9;&#x8C61;&#x3002;</span>
  () =&gt; <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;./my-async-component&apos;</span>)
)
</code></pre>
<p>&#x53E6;&#x4E00;&#x79CD;&#x662F;&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#xFF0C;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> AsyncComp = () =&gt; ({
  <span class="hljs-comment">// &#x9700;&#x8981;&#x52A0;&#x8F7D;&#x7684;&#x7EC4;&#x4EF6;&#x3002;&#x5E94;&#x5F53;&#x662F;&#x4E00;&#x4E2A; Promise</span>
  component: <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;./MyComp.vue&apos;</span>),
  <span class="hljs-comment">// &#x52A0;&#x8F7D;&#x4E2D;&#x5E94;&#x5F53;&#x6E32;&#x67D3;&#x7684;&#x7EC4;&#x4EF6;</span>
  loading: LoadingComp,
  <span class="hljs-comment">// &#x51FA;&#x9519;&#x65F6;&#x6E32;&#x67D3;&#x7684;&#x7EC4;&#x4EF6;</span>
  error: ErrorComp,
  <span class="hljs-comment">// &#x6E32;&#x67D3;&#x52A0;&#x8F7D;&#x4E2D;&#x7EC4;&#x4EF6;&#x524D;&#x7684;&#x7B49;&#x5F85;&#x65F6;&#x95F4;&#x3002;&#x9ED8;&#x8BA4;&#xFF1A;200ms&#x3002;</span>
  delay: <span class="hljs-number">200</span>,
  <span class="hljs-comment">// &#x6700;&#x957F;&#x7B49;&#x5F85;&#x65F6;&#x95F4;&#x3002;&#x8D85;&#x51FA;&#x6B64;&#x65F6;&#x95F4;&#x5219;&#x6E32;&#x67D3;&#x9519;&#x8BEF;&#x7EC4;&#x4EF6;&#x3002;&#x9ED8;&#x8BA4;&#xFF1A;Infinity</span>
  timeout: <span class="hljs-number">3000</span>
})
Vue.component(<span class="hljs-string">&apos;async-example&apos;</span>, AsyncComp)
</code></pre>
<p>&#x90A3;&#x4E48;&#x89E3;&#x4E0B;&#x6765;&#xFF0C;&#x6211;&#x4EEC;&#x5C31;&#x6839;&#x636E;&#x8FD9; 3 &#x79CD;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x6765;&#x5206;&#x522B;&#x53BB;&#x5206;&#x6790; <code>resolveAsyncComponent</code> &#x7684;&#x903B;&#x8F91;&#x3002;</p>
<h2 id="&#x666E;&#x901A;&#x51FD;&#x6570;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><a name="&#x666E;&#x901A;&#x51FD;&#x6570;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x666E;&#x901A;&#x51FD;&#x6570;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x666E;&#x901A;&#x51FD;&#x6570;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;" class="plugin-anchor" href="#&#x666E;&#x901A;&#x51FD;&#x6570;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x666E;&#x901A;&#x51FD;&#x6570;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;</h2>
<p>&#x9488;&#x5BF9;&#x666E;&#x901A;&#x51FD;&#x6570;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x524D;&#x9762;&#x51E0;&#x4E2A; if &#x5224;&#x65AD;&#x53EF;&#x4EE5;&#x5FFD;&#x7565;&#xFF0C;&#x5B83;&#x4EEC;&#x662F;&#x4E3A;&#x9AD8;&#x7EA7;&#x7EC4;&#x4EF6;&#x6240;&#x7528;&#xFF0C;&#x5BF9;&#x4E8E; <code>factory.contexts</code> &#x7684;&#x5224;&#x65AD;&#xFF0C;&#x662F;&#x8003;&#x8651;&#x5230;&#x591A;&#x4E2A;&#x5730;&#x65B9;&#x540C;&#x65F6;&#x521D;&#x59CB;&#x5316;&#x4E00;&#x4E2A;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#xFF0C;&#x90A3;&#x4E48;&#x5B83;&#x7684;&#x5B9E;&#x9645;&#x52A0;&#x8F7D;&#x5E94;&#x8BE5;&#x53EA;&#x6709;&#x4E00;&#x6B21;&#x3002;&#x63A5;&#x7740;&#x8FDB;&#x5165;&#x5B9E;&#x9645;&#x52A0;&#x8F7D;&#x903B;&#x8F91;&#xFF0C;&#x5B9A;&#x4E49;&#x4E86; <code>forceRender</code>&#x3001;<code>resolve</code> &#x548C; <code>reject</code> &#x51FD;&#x6570;&#xFF0C;&#x6CE8;&#x610F; <code>resolve</code> &#x548C; <code>reject</code> &#x51FD;&#x6570;&#x7528; <code>once</code> &#x51FD;&#x6570;&#x505A;&#x4E86;&#x4E00;&#x5C42;&#x5305;&#x88C5;&#xFF0C;&#x5B83;&#x7684;&#x5B9A;&#x4E49;&#x5728; <code>src/shared/util.js</code> &#x4E2D;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-comment">/**
 * Ensure a function is called only once.
 */</span>
<span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">once</span> (<span class="hljs-params">fn: Function</span>): <span class="hljs-title">Function</span> </span>{
  <span class="hljs-keyword">let</span> called = <span class="hljs-literal">false</span>
  <span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">if</span> (!called) {
      called = <span class="hljs-literal">true</span>
      fn.apply(<span class="hljs-keyword">this</span>, <span class="hljs-built_in">arguments</span>)
    }
  }
}
</code></pre>
<p><code>once</code> &#x903B;&#x8F91;&#x975E;&#x5E38;&#x7B80;&#x5355;&#xFF0C;&#x4F20;&#x5165;&#x4E00;&#x4E2A;&#x51FD;&#x6570;&#xFF0C;&#x5E76;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A;&#x65B0;&#x51FD;&#x6570;&#xFF0C;&#x5B83;&#x975E;&#x5E38;&#x5DE7;&#x5999;&#x5730;&#x5229;&#x7528;&#x95ED;&#x5305;&#x548C;&#x4E00;&#x4E2A;&#x6807;&#x5FD7;&#x4F4D;&#x4FDD;&#x8BC1;&#x4E86;&#x5B83;&#x5305;&#x88C5;&#x7684;&#x51FD;&#x6570;&#x53EA;&#x4F1A;&#x6267;&#x884C;&#x4E00;&#x6B21;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x786E;&#x4FDD; <code>resolve</code> &#x548C; <code>reject</code> &#x51FD;&#x6570;&#x53EA;&#x6267;&#x884C;&#x4E00;&#x6B21;&#x3002;</p>
<p>&#x63A5;&#x4E0B;&#x6765;&#x6267;&#x884C; <code>const res = factory(resolve, reject)</code> &#x903B;&#x8F91;&#xFF0C;&#x8FD9;&#x5757;&#x513F;&#x5C31;&#x662F;&#x6267;&#x884C;&#x6211;&#x4EEC;&#x7EC4;&#x4EF6;&#x7684;&#x5DE5;&#x5382;&#x51FD;&#x6570;&#xFF0C;&#x540C;&#x65F6;&#x628A; <code>resolve</code> &#x548C; <code>reject</code> &#x51FD;&#x6570;&#x4F5C;&#x4E3A;&#x53C2;&#x6570;&#x4F20;&#x5165;&#xFF0C;&#x7EC4;&#x4EF6;&#x7684;&#x5DE5;&#x5382;&#x51FD;&#x6570;&#x901A;&#x5E38;&#x4F1A;&#x5148;&#x53D1;&#x9001;&#x8BF7;&#x6C42;&#x53BB;&#x52A0;&#x8F7D;&#x6211;&#x4EEC;&#x7684;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7684; JS &#x6587;&#x4EF6;&#xFF0C;&#x62FF;&#x5230;&#x7EC4;&#x4EF6;&#x5B9A;&#x4E49;&#x7684;&#x5BF9;&#x8C61; <code>res</code> &#x540E;&#xFF0C;&#x6267;&#x884C; <code>resolve(res)</code> &#x903B;&#x8F91;&#xFF0C;&#x5B83;&#x4F1A;&#x5148;&#x6267;&#x884C; <code>factory.resolved = ensureCtor(res, baseCtor)</code>&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">ensureCtor</span> (<span class="hljs-params">comp: any, base</span>) </span>{
  <span class="hljs-keyword">if</span> (
    comp.__esModule ||
    (hasSymbol &amp;&amp; comp[<span class="hljs-built_in">Symbol</span>.toStringTag] === <span class="hljs-string">&apos;Module&apos;</span>)
  ) {
    comp = comp.default
  }
  <span class="hljs-keyword">return</span> isObject(comp)
    ? base.extend(comp)
    : comp
}
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x51FD;&#x6570;&#x76EE;&#x7684;&#x662F;&#x4E3A;&#x4E86;&#x4FDD;&#x8BC1;&#x80FD;&#x627E;&#x5230;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6; JS &#x5B9A;&#x4E49;&#x7684;&#x7EC4;&#x4EF6;&#x5BF9;&#x8C61;&#xFF0C;&#x5E76;&#x4E14;&#x5982;&#x679C;&#x5B83;&#x662F;&#x4E00;&#x4E2A;&#x666E;&#x901A;&#x5BF9;&#x8C61;&#xFF0C;&#x5219;&#x8C03;&#x7528; <code>Vue.extend</code> &#x628A;&#x5B83;&#x8F6C;&#x6362;&#x6210;&#x4E00;&#x4E2A;&#x7EC4;&#x4EF6;&#x7684;&#x6784;&#x9020;&#x51FD;&#x6570;&#x3002;</p>
<p><code>resolve</code> &#x903B;&#x8F91;&#x6700;&#x540E;&#x5224;&#x65AD;&#x4E86; <code>sync</code>&#xFF0C;&#x663E;&#x7136;&#x6211;&#x4EEC;&#x8FD9;&#x4E2A;&#x573A;&#x666F;&#x4E0B; <code>sync</code> &#x4E3A; false&#xFF0C;&#x90A3;&#x4E48;&#x5C31;&#x4F1A;&#x6267;&#x884C; <code>forceRender</code> &#x51FD;&#x6570;&#xFF0C;&#x5B83;&#x4F1A;&#x904D;&#x5386; <code>factory.contexts</code>&#xFF0C;&#x62FF;&#x5230;&#x6BCF;&#x4E00;&#x4E2A;&#x8C03;&#x7528;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x4F8B; <code>vm</code>, &#x6267;&#x884C; <code>vm.$forceUpdate()</code> &#x65B9;&#x6CD5;&#xFF0C;&#x5B83;&#x7684;&#x5B9A;&#x4E49;&#x5728; <code>src/core/instance/lifecycle.js</code> &#x4E2D;&#xFF1A;</p>
<pre><code class="lang-js">Vue.prototype.$forceUpdate = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
  <span class="hljs-keyword">const</span> vm: Component = <span class="hljs-keyword">this</span>
  <span class="hljs-keyword">if</span> (vm._watcher) {
    vm._watcher.update()
  }
}
</code></pre>
<p><code>$forceUpdate</code> &#x7684;&#x903B;&#x8F91;&#x975E;&#x5E38;&#x7B80;&#x5355;&#xFF0C;&#x5C31;&#x662F;&#x8C03;&#x7528;&#x6E32;&#x67D3; <code>watcher</code> &#x7684; <code>update</code> &#x65B9;&#x6CD5;&#xFF0C;&#x8BA9;&#x6E32;&#x67D3; <code>watcher</code> &#x5BF9;&#x5E94;&#x7684;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x6267;&#x884C;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x89E6;&#x53D1;&#x4E86;&#x7EC4;&#x4EF6;&#x7684;&#x91CD;&#x65B0;&#x6E32;&#x67D3;&#x3002;&#x4E4B;&#x6240;&#x4EE5;&#x8FD9;&#x4E48;&#x505A;&#x662F;&#x56E0;&#x4E3A; Vue &#x901A;&#x5E38;&#x662F;&#x6570;&#x636E;&#x9A71;&#x52A8;&#x89C6;&#x56FE;&#x91CD;&#x65B0;&#x6E32;&#x67D3;&#xFF0C;&#x4F46;&#x662F;&#x5728;&#x6574;&#x4E2A;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x8FC7;&#x7A0B;&#x4E2D;&#x662F;&#x6CA1;&#x6709;&#x6570;&#x636E;&#x53D1;&#x751F;&#x53D8;&#x5316;&#x7684;&#xFF0C;&#x6240;&#x4EE5;&#x901A;&#x8FC7;&#x6267;&#x884C; <code>$forceUpdate</code> &#x53EF;&#x4EE5;&#x5F3A;&#x5236;&#x7EC4;&#x4EF6;&#x91CD;&#x65B0;&#x6E32;&#x67D3;&#x4E00;&#x6B21;&#x3002;</p>
<h2 id="promise-&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><a name="promise-&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#promise-&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="promise-&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;" class="plugin-anchor" href="#promise-&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a><code>Promise</code> &#x5F02;&#x6B65;&#x7EC4;&#x4EF6;</h2>
<pre><code class="lang-js">Vue.component(
  <span class="hljs-string">&apos;async-webpack-example&apos;</span>,
  <span class="hljs-comment">// &#x8BE5; `import` &#x51FD;&#x6570;&#x8FD4;&#x56DE;&#x4E00;&#x4E2A; `Promise` &#x5BF9;&#x8C61;&#x3002;</span>
  () =&gt; <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;./my-async-component&apos;</span>)
)
</code></pre>
<p>webpack 2+ &#x652F;&#x6301;&#x4E86;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684;&#x8BED;&#x6CD5;&#x7CD6;&#xFF1A;<code>() =&gt; import(&apos;./my-async-component&apos;)</code>&#xFF0C;&#x5F53;&#x6267;&#x884C;&#x5B8C; <code>res = factory(resolve, reject)</code>&#xFF0C;&#x8FD4;&#x56DE;&#x7684;&#x503C;&#x5C31;&#x662F; <code>import(&apos;./my-async-component&apos;)</code> &#x7684;&#x8FD4;&#x56DE;&#x503C;&#xFF0C;&#x5B83;&#x662F;&#x4E00;&#x4E2A; <code>Promise</code> &#x5BF9;&#x8C61;&#x3002;&#x63A5;&#x7740;&#x8FDB;&#x5165; if &#x6761;&#x4EF6;&#xFF0C;&#x53C8;&#x5224;&#x65AD;&#x4E86; <code>typeof res.then === &apos;function&apos;)</code>&#xFF0C;&#x6761;&#x4EF6;&#x6EE1;&#x8DB3;&#xFF0C;&#x6267;&#x884C;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span> (isUndef(factory.resolved)) {
  res.then(resolve, reject)
}
</code></pre>
<p>&#x5F53;&#x7EC4;&#x4EF6;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x6210;&#x529F;&#x540E;&#xFF0C;&#x6267;&#x884C; <code>resolve</code>&#xFF0C;&#x52A0;&#x8F7D;&#x5931;&#x8D25;&#x5219;&#x6267;&#x884C; <code>reject</code>&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x975E;&#x5E38;&#x5DE7;&#x5999;&#x5730;&#x5B9E;&#x73B0;&#x4E86;&#x914D;&#x5408; webpack 2+ &#x7684;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7EC4;&#x4EF6;&#x7684;&#x65B9;&#x5F0F;&#xFF08;<code>Promise</code>&#xFF09;&#x52A0;&#x8F7D;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x3002;</p>
<h2 id="&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><a name="&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;" class="anchor-navigation-ex-anchor" href="#&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;" class="plugin-anchor" href="#&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;</h2>
<p>&#x7531;&#x4E8E;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7EC4;&#x4EF6;&#x9700;&#x8981;&#x52A8;&#x6001;&#x52A0;&#x8F7D; JS&#xFF0C;&#x6709;&#x4E00;&#x5B9A;&#x7F51;&#x7EDC;&#x5EF6;&#x65F6;&#xFF0C;&#x800C;&#x4E14;&#x6709;&#x52A0;&#x8F7D;&#x5931;&#x8D25;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x6240;&#x4EE5;&#x901A;&#x5E38;&#x6211;&#x4EEC;&#x5728;&#x5F00;&#x53D1;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x76F8;&#x5173;&#x903B;&#x8F91;&#x7684;&#x65F6;&#x5019;&#x9700;&#x8981;&#x8BBE;&#x8BA1; loading &#x7EC4;&#x4EF6;&#x548C; error &#x7EC4;&#x4EF6;&#xFF0C;&#x5E76;&#x5728;&#x9002;&#x5F53;&#x7684;&#x65F6;&#x673A;&#x6E32;&#x67D3;&#x5B83;&#x4EEC;&#x3002;Vue.js 2.3+ &#x652F;&#x6301;&#x4E86;&#x4E00;&#x79CD;&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7684;&#x65B9;&#x5F0F;&#xFF0C;&#x5B83;&#x901A;&#x8FC7;&#x4E00;&#x4E2A;&#x7B80;&#x5355;&#x7684;&#x5BF9;&#x8C61;&#x914D;&#x7F6E;&#xFF0C;&#x5E2E;&#x4F60;&#x641E;&#x5B9A; loading &#x7EC4;&#x4EF6;&#x548C; error &#x7EC4;&#x4EF6;&#x7684;&#x6E32;&#x67D3;&#x65F6;&#x673A;&#xFF0C;&#x4F60;&#x5B8C;&#x5168;&#x4E0D;&#x7528;&#x5173;&#x5FC3;&#x7EC6;&#x8282;&#xFF0C;&#x975E;&#x5E38;&#x65B9;&#x4FBF;&#x3002;&#x63A5;&#x4E0B;&#x6765;&#x6211;&#x4EEC;&#x5C31;&#x4ECE;&#x6E90;&#x7801;&#x7684;&#x89D2;&#x5EA6;&#x6765;&#x5206;&#x6790;&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x662F;&#x600E;&#x4E48;&#x5B9E;&#x73B0;&#x7684;&#x3002;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> AsyncComp = () =&gt; ({
  <span class="hljs-comment">// &#x9700;&#x8981;&#x52A0;&#x8F7D;&#x7684;&#x7EC4;&#x4EF6;&#x3002;&#x5E94;&#x5F53;&#x662F;&#x4E00;&#x4E2A; Promise</span>
  component: <span class="hljs-keyword">import</span>(<span class="hljs-string">&apos;./MyComp.vue&apos;</span>),
  <span class="hljs-comment">// &#x52A0;&#x8F7D;&#x4E2D;&#x5E94;&#x5F53;&#x6E32;&#x67D3;&#x7684;&#x7EC4;&#x4EF6;</span>
  loading: LoadingComp,
  <span class="hljs-comment">// &#x51FA;&#x9519;&#x65F6;&#x6E32;&#x67D3;&#x7684;&#x7EC4;&#x4EF6;</span>
  error: ErrorComp,
  <span class="hljs-comment">// &#x6E32;&#x67D3;&#x52A0;&#x8F7D;&#x4E2D;&#x7EC4;&#x4EF6;&#x524D;&#x7684;&#x7B49;&#x5F85;&#x65F6;&#x95F4;&#x3002;&#x9ED8;&#x8BA4;&#xFF1A;200ms&#x3002;</span>
  delay: <span class="hljs-number">200</span>,
  <span class="hljs-comment">// &#x6700;&#x957F;&#x7B49;&#x5F85;&#x65F6;&#x95F4;&#x3002;&#x8D85;&#x51FA;&#x6B64;&#x65F6;&#x95F4;&#x5219;&#x6E32;&#x67D3;&#x9519;&#x8BEF;&#x7EC4;&#x4EF6;&#x3002;&#x9ED8;&#x8BA4;&#xFF1A;Infinity</span>
  timeout: <span class="hljs-number">3000</span>
})
Vue.component(<span class="hljs-string">&apos;async-example&apos;</span>, AsyncComp)
</code></pre>
<p>&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7684;&#x521D;&#x59CB;&#x5316;&#x903B;&#x8F91;&#x548C;&#x666E;&#x901A;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x4E00;&#x6837;&#xFF0C;&#x4E5F;&#x662F;&#x6267;&#x884C; <code>resolveAsyncComponent</code>&#xFF0C;&#x5F53;&#x6267;&#x884C;&#x5B8C; <code>res = factory(resolve, reject)</code>&#xFF0C;&#x8FD4;&#x56DE;&#x503C;&#x5C31;&#x662F;&#x5B9A;&#x4E49;&#x7684;&#x7EC4;&#x4EF6;&#x5BF9;&#x8C61;&#xFF0C;&#x663E;&#x7136;&#x6EE1;&#x8DB3; <code>else if (isDef(res.component) &amp;&amp; typeof res.component.then === &apos;function&apos;)</code> &#x7684;&#x903B;&#x8F91;&#xFF0C;&#x63A5;&#x7740;&#x6267;&#x884C; <code>res.component.then(resolve, reject)</code>&#xFF0C;&#x5F53;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;&#x540E;&#xFF0C;&#x6267;&#x884C; <code>resolve</code>&#xFF0C;&#x5931;&#x8D25;&#x6267;&#x884C; <code>reject</code>&#x3002;</p>
<p>&#x56E0;&#x4E3A;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x662F;&#x4E00;&#x4E2A;&#x5F02;&#x6B65;&#x8FC7;&#x7A0B;&#xFF0C;&#x5B83;&#x63A5;&#x7740;&#x53C8;&#x540C;&#x6B65;&#x6267;&#x884C;&#x4E86;&#x5982;&#x4E0B;&#x903B;&#x8F91;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span> (isDef(res.error)) {
  factory.errorComp = ensureCtor(res.error, baseCtor)
}

<span class="hljs-keyword">if</span> (isDef(res.loading)) {
  factory.loadingComp = ensureCtor(res.loading, baseCtor)
  <span class="hljs-keyword">if</span> (res.delay === <span class="hljs-number">0</span>) {
    factory.loading = <span class="hljs-literal">true</span>
  } <span class="hljs-keyword">else</span> {
    setTimeout(() =&gt; {
      <span class="hljs-keyword">if</span> (isUndef(factory.resolved) &amp;&amp; isUndef(factory.error)) {
        factory.loading = <span class="hljs-literal">true</span>
        forceRender()
      }
    }, res.delay || <span class="hljs-number">200</span>)
  }
}

<span class="hljs-keyword">if</span> (isDef(res.timeout)) {
  setTimeout(() =&gt; {
    <span class="hljs-keyword">if</span> (isUndef(factory.resolved)) {
      reject(
        process.env.NODE_ENV !== <span class="hljs-string">&apos;production&apos;</span>
          ? <span class="hljs-string">`timeout (<span class="hljs-subst">${res.timeout}</span>ms)`</span>
          : <span class="hljs-literal">null</span>
      )
    }
  }, res.timeout)
}
</code></pre>
<p>&#x5148;&#x5224;&#x65AD; <code>res.error</code> &#x662F;&#x5426;&#x5B9A;&#x4E49;&#x4E86; error &#x7EC4;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x7684;&#x8BDD;&#x5219;&#x8D4B;&#x503C;&#x7ED9; <code>factory.errorComp</code>&#x3002;
&#x63A5;&#x7740;&#x5224;&#x65AD; <code>res.loading</code> &#x662F;&#x5426;&#x5B9A;&#x4E49;&#x4E86; loading &#x7EC4;&#x4EF6;&#xFF0C;&#x5982;&#x679C;&#x6709;&#x7684;&#x8BDD;&#x5219;&#x8D4B;&#x503C;&#x7ED9; <code>factory.loadingComp</code>&#xFF0C;&#x5982;&#x679C;&#x8BBE;&#x7F6E;&#x4E86; <code>res.delay</code> &#x4E14;&#x4E3A; 0&#xFF0C;&#x5219;&#x8BBE;&#x7F6E; <code>factory.loading = true</code>&#xFF0C;&#x5426;&#x5219;&#x5EF6;&#x65F6; <code>delay</code> &#x7684;&#x65F6;&#x95F4;&#x6267;&#x884C;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span> (isUndef(factory.resolved) &amp;&amp; isUndef(factory.error)) {
    factory.loading = <span class="hljs-literal">true</span>
    forceRender()
}
</code></pre>
<p>&#x6700;&#x540E;&#x5224;&#x65AD; <code>res.timeout</code>&#xFF0C;&#x5982;&#x679C;&#x914D;&#x7F6E;&#x4E86;&#x8BE5;&#x9879;&#xFF0C;&#x5219;&#x5728; <code>res.timout</code> &#x65F6;&#x95F4;&#x540E;&#xFF0C;&#x5982;&#x679C;&#x7EC4;&#x4EF6;&#x6CA1;&#x6709;&#x6210;&#x529F;&#x52A0;&#x8F7D;&#xFF0C;&#x6267;&#x884C; <code>reject</code>&#x3002;</p>
<p>&#x5728; <code>resolveAsyncComponent</code> &#x7684;&#x6700;&#x540E;&#x6709;&#x4E00;&#x6BB5;&#x903B;&#x8F91;&#xFF1A;</p>
<pre><code class="lang-js">sync = <span class="hljs-literal">false</span>
<span class="hljs-keyword">return</span> factory.loading
  ? factory.loadingComp
  : factory.resolved
</code></pre>
<p>&#x5982;&#x679C; <code>delay</code> &#x914D;&#x7F6E;&#x4E3A; 0&#xFF0C;&#x5219;&#x8FD9;&#x6B21;&#x76F4;&#x63A5;&#x6E32;&#x67D3; loading &#x7EC4;&#x4EF6;&#xFF0C;&#x5426;&#x5219;&#x5219;&#x5EF6;&#x65F6; <code>delay</code> &#x6267;&#x884C; <code>forceRender</code>&#xFF0C;&#x90A3;&#x4E48;&#x53C8;&#x4F1A;&#x518D;&#x4E00;&#x6B21;&#x6267;&#x884C;&#x5230; <code>resolveAsyncComponent</code>&#x3002;</p>
<p>&#x90A3;&#x4E48;&#x8FD9;&#x65F6;&#x5019;&#x6211;&#x4EEC;&#x6709;&#x51E0;&#x79CD;&#x60C5;&#x51B5;&#xFF0C;&#x6309;&#x903B;&#x8F91;&#x7684;&#x6267;&#x884C;&#x987A;&#x5E8F;&#xFF0C;&#x5BF9;&#x4E0D;&#x540C;&#x7684;&#x60C5;&#x51B5;&#x505A;&#x5224;&#x65AD;&#x3002;</p>
<h3 id="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x5931;&#x8D25;"><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x5931;&#x8D25;" class="anchor-navigation-ex-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x5931;&#x8D25;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x5931;&#x8D25;" class="plugin-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x5931;&#x8D25;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x5931;&#x8D25;</h3>
<p>&#x5F53;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x5931;&#x8D25;&#xFF0C;&#x4F1A;&#x6267;&#x884C; <code>reject</code> &#x51FD;&#x6570;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> reject = once(reason =&gt; {
  process.env.NODE_ENV !== <span class="hljs-string">&apos;production&apos;</span> &amp;&amp; warn(
    <span class="hljs-string">`Failed to resolve async component: <span class="hljs-subst">${String(factory)}</span>`</span> +
    (reason ? <span class="hljs-string">`\nReason: <span class="hljs-subst">${reason}</span>`</span> : <span class="hljs-string">&apos;&apos;</span>)
  )
  <span class="hljs-keyword">if</span> (isDef(factory.errorComp)) {
    factory.error = <span class="hljs-literal">true</span>
    forceRender()
  }
})
</code></pre>
<p>&#x8FD9;&#x4E2A;&#x65F6;&#x5019;&#x4F1A;&#x628A; <code>factory.error</code> &#x8BBE;&#x7F6E;&#x4E3A; <code>true</code>&#xFF0C;&#x540C;&#x65F6;&#x6267;&#x884C; <code>forceRender()</code> &#x518D;&#x6B21;&#x6267;&#x884C;&#x5230; <code>resolveAsyncComponent</code>&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span> (isTrue(factory.error) &amp;&amp; isDef(factory.errorComp)) {
  <span class="hljs-keyword">return</span> factory.errorComp
}
</code></pre>
<p>&#x90A3;&#x4E48;&#x8FD9;&#x4E2A;&#x65F6;&#x5019;&#x5C31;&#x8FD4;&#x56DE; <code>factory.errorComp</code>&#xFF0C;&#x76F4;&#x63A5;&#x6E32;&#x67D3; error &#x7EC4;&#x4EF6;&#x3002;</p>
<h3 id="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;"><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;" class="anchor-navigation-ex-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;" class="plugin-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;</h3>
<p>&#x5F53;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x6210;&#x529F;&#xFF0C;&#x4F1A;&#x6267;&#x884C; <code>resolve</code> &#x51FD;&#x6570;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">const</span> resolve = once((res: <span class="hljs-built_in">Object</span> | Class&lt;Component&gt;) =&gt; {
  factory.resolved = ensureCtor(res, baseCtor)
  <span class="hljs-keyword">if</span> (!sync) {
    forceRender()
  }
})
</code></pre>
<p>&#x9996;&#x5148;&#x628A;&#x52A0;&#x8F7D;&#x7ED3;&#x679C;&#x7F13;&#x5B58;&#x5230; <code>factory.resolved</code> &#x4E2D;&#xFF0C;&#x8FD9;&#x4E2A;&#x65F6;&#x5019;&#x56E0;&#x4E3A; <code>sync</code> &#x5DF2;&#x7ECF;&#x4E3A; false&#xFF0C;&#x5219;&#x6267;&#x884C; <code>forceRender()</code> &#x518D;&#x6B21;&#x6267;&#x884C;&#x5230; <code>resolveAsyncComponent</code>&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span> (isDef(factory.resolved)) {
  <span class="hljs-keyword">return</span> factory.resolved
}
</code></pre>
<p>&#x90A3;&#x4E48;&#x8FD9;&#x4E2A;&#x65F6;&#x5019;&#x76F4;&#x63A5;&#x8FD4;&#x56DE; <code>factory.resolved</code>&#xFF0C;&#x6E32;&#x67D3;&#x6210;&#x529F;&#x52A0;&#x8F7D;&#x7684;&#x7EC4;&#x4EF6;&#x3002;</p>
<h3 id="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x4E2D;"><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x4E2D;" class="anchor-navigation-ex-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x4E2D;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x4E2D;" class="plugin-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x4E2D;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x4E2D;</h3>
<p>&#x5982;&#x679C;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x4E2D;&#x5E76;&#x672A;&#x8FD4;&#x56DE;&#xFF0C;&#x8FD9;&#x65F6;&#x5019;&#x4F1A;&#x8D70;&#x5230;&#x8FD9;&#x4E2A;&#x903B;&#x8F91;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">if</span> (isTrue(factory.loading) &amp;&amp; isDef(factory.loadingComp)) {
  <span class="hljs-keyword">return</span> factory.loadingComp
}
</code></pre>
<p>&#x90A3;&#x4E48;&#x5219;&#x4F1A;&#x8FD4;&#x56DE; <code>factory.loadingComp</code>&#xFF0C;&#x6E32;&#x67D3; loading &#x7EC4;&#x4EF6;&#x3002;</p>
<h3 id="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x8D85;&#x65F6;"><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x8D85;&#x65F6;" class="anchor-navigation-ex-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x8D85;&#x65F6;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x8D85;&#x65F6;" class="plugin-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x8D85;&#x65F6;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x52A0;&#x8F7D;&#x8D85;&#x65F6;</h3>
<p>&#x5982;&#x679C;&#x8D85;&#x65F6;&#xFF0C;&#x5219;&#x8D70;&#x5230;&#x4E86; <code>reject</code> &#x903B;&#x8F91;&#xFF0C;&#x4E4B;&#x540E;&#x903B;&#x8F91;&#x548C;&#x52A0;&#x8F7D;&#x5931;&#x8D25;&#x4E00;&#x6837;&#xFF0C;&#x6E32;&#x67D3; error &#x7EC4;&#x4EF6;&#x3002;</p>
<h2 id="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;-patch"><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;-patch" class="anchor-navigation-ex-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;-patch"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;-patch" class="plugin-anchor" href="#&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;-patch"><i class="fa fa-link" aria-hidden="true"></i></a>&#x5F02;&#x6B65;&#x7EC4;&#x4EF6; patch</h2>
<p>&#x56DE;&#x5230; <code>createComponent</code> &#x7684;&#x903B;&#x8F91;&#xFF1A;</p>
<pre><code class="lang-js">Ctor = resolveAsyncComponent(asyncFactory, baseCtor, context)
<span class="hljs-keyword">if</span> (Ctor === <span class="hljs-literal">undefined</span>) {
  <span class="hljs-keyword">return</span> createAsyncPlaceholder(
    asyncFactory,
    data,
    context,
    children,
    tag
  )
}
</code></pre>
<p>&#x5982;&#x679C;&#x662F;&#x7B2C;&#x4E00;&#x6B21;&#x6267;&#x884C; <code>resolveAsyncComponent</code>&#xFF0C;&#x9664;&#x975E;&#x4F7F;&#x7528;&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6; <code>0 delay</code> &#x53BB;&#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A; loading &#x7EC4;&#x4EF6;&#xFF0C;&#x5426;&#x5219;&#x8FD4;&#x56DE;&#x662F; <code>undefiend</code>&#xFF0C;&#x63A5;&#x7740;&#x901A;&#x8FC7; <code>createAsyncPlaceholder</code> &#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x6CE8;&#x91CA;&#x8282;&#x70B9;&#x4F5C;&#x4E3A;&#x5360;&#x4F4D;&#x7B26;&#x3002;&#x5B83;&#x7684;&#x5B9A;&#x4E49;&#x5728; <code>src/core/vdom/helpers/resolve-async-components.js</code> &#x4E2D;&#xFF1A;</p>
<pre><code class="lang-js"><span class="hljs-keyword">export</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">createAsyncPlaceholder</span> (<span class="hljs-params">
  factory: Function,
  data: ?VNodeData,
  context: Component,
  children: ?Array&lt;VNode&gt;,
  tag: ?string
</span>): <span class="hljs-title">VNode</span> </span>{
  <span class="hljs-keyword">const</span> node = createEmptyVNode()
  node.asyncFactory = factory
  node.asyncMeta = { data, context, children, tag }
  <span class="hljs-keyword">return</span> node
}
</code></pre>
<p>&#x5B9E;&#x9645;&#x4E0A;&#x5C31;&#x662F;&#x5C31;&#x662F;&#x521B;&#x5EFA;&#x4E86;&#x4E00;&#x4E2A;&#x5360;&#x4F4D;&#x7684;&#x6CE8;&#x91CA; VNode&#xFF0C;&#x540C;&#x65F6;&#x628A; <code>asyncFactory</code> &#x548C; <code>asyncMeta</code> &#x8D4B;&#x503C;&#x7ED9;&#x5F53;&#x524D; <code>vnode</code>&#x3002;</p>
<p>&#x5F53;&#x6267;&#x884C; <code>forceRender</code> &#x7684;&#x65F6;&#x5019;&#xFF0C;&#x4F1A;&#x89E6;&#x53D1;&#x7EC4;&#x4EF6;&#x7684;&#x91CD;&#x65B0;&#x6E32;&#x67D3;&#xFF0C;&#x90A3;&#x4E48;&#x4F1A;&#x518D;&#x4E00;&#x6B21;&#x6267;&#x884C; <code>resolveAsyncComponent</code>&#xFF0C;&#x8FD9;&#x65F6;&#x5019;&#x5C31;&#x4F1A;&#x6839;&#x636E;&#x4E0D;&#x540C;&#x7684;&#x60C5;&#x51B5;&#xFF0C;&#x53EF;&#x80FD;&#x8FD4;&#x56DE; loading&#x3001;error &#x6216;&#x6210;&#x529F;&#x52A0;&#x8F7D;&#x7684;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#xFF0C;&#x8FD4;&#x56DE;&#x503C;&#x4E0D;&#x4E3A; <code>undefined</code>&#xFF0C;&#x56E0;&#x6B64;&#x5C31;&#x8D70;&#x6B63;&#x5E38;&#x7684;&#x7EC4;&#x4EF6; <code>render</code>&#x3001;<code>patch</code> &#x8FC7;&#x7A0B;&#xFF0C;&#x4E0E;&#x7EC4;&#x4EF6;&#x7B2C;&#x4E00;&#x6B21;&#x6E32;&#x67D3;&#x6D41;&#x7A0B;&#x4E0D;&#x4E00;&#x6837;&#xFF0C;&#x8FD9;&#x4E2A;&#x65F6;&#x5019;&#x662F;&#x5B58;&#x5728;&#x65B0;&#x65E7; <code>vnode</code> &#x7684;&#xFF0C;&#x4E0B;&#x4E00;&#x7AE0;&#x6211;&#x4F1A;&#x5206;&#x6790;&#x7EC4;&#x4EF6;&#x66F4;&#x65B0;&#x7684; <code>patch</code> &#x8FC7;&#x7A0B;&#x3002;</p>
<h2 id="&#x603B;&#x7ED3;"><a name="&#x603B;&#x7ED3;" class="anchor-navigation-ex-anchor" href="#&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a><a name="&#x603B;&#x7ED3;" class="plugin-anchor" href="#&#x603B;&#x7ED3;"><i class="fa fa-link" aria-hidden="true"></i></a>&#x603B;&#x7ED3;</h2>
<p>&#x901A;&#x8FC7;&#x4EE5;&#x4E0A;&#x4EE3;&#x7801;&#x5206;&#x6790;&#xFF0C;&#x6211;&#x4EEC;&#x5BF9; Vue &#x7684;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;&#x6709;&#x4E86;&#x6DF1;&#x5165;&#x7684;&#x4E86;&#x89E3;&#xFF0C;&#x77E5;&#x9053;&#x4E86; 3 &#x79CD;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#xFF0C;&#x5E76;&#x4E14;&#x770B;&#x5230;&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7684;&#x5B9E;&#x73B0;&#x662F;&#x975E;&#x5E38;&#x5DE7;&#x5999;&#x7684;&#xFF0C;&#x5B83;&#x5B9E;&#x73B0;&#x4E86; loading&#x3001;resolve&#x3001;reject&#x3001;timeout 4 &#x79CD;&#x72B6;&#x6001;&#x3002;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x5B9E;&#x73B0;&#x7684;&#x672C;&#x8D28;&#x662F; 2 &#x6B21;&#x6E32;&#x67D3;&#xFF0C;&#x9664;&#x4E86; 0 delay &#x7684;&#x9AD8;&#x7EA7;&#x5F02;&#x6B65;&#x7EC4;&#x4EF6;&#x7B2C;&#x4E00;&#x6B21;&#x76F4;&#x63A5;&#x6E32;&#x67D3;&#x6210; loading &#x7EC4;&#x4EF6;&#x5916;&#xFF0C;&#x5176;&#x5B83;&#x90FD;&#x662F;&#x7B2C;&#x4E00;&#x6B21;&#x6E32;&#x67D3;&#x751F;&#x6210;&#x4E00;&#x4E2A;&#x6CE8;&#x91CA;&#x8282;&#x70B9;&#xFF0C;&#x5F53;&#x5F02;&#x6B65;&#x83B7;&#x53D6;&#x7EC4;&#x4EF6;&#x6210;&#x529F;&#x540E;&#xFF0C;&#x518D;&#x901A;&#x8FC7; <code>forceRender</code> &#x5F3A;&#x5236;&#x91CD;&#x65B0;&#x6E32;&#x67D3;&#xFF0C;&#x8FD9;&#x6837;&#x5C31;&#x80FD;&#x6B63;&#x786E;&#x6E32;&#x67D3;&#x51FA;&#x6211;&#x4EEC;&#x5F02;&#x6B65;&#x52A0;&#x8F7D;&#x7684;&#x7EC4;&#x4EF6;&#x4E86;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../" class="navigation navigation-prev " aria-label="Previous page: Introduction">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="gitbook.html" class="navigation navigation-next " aria-label="Next page: GitBook is nice">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"Writing is nice","level":"1.2","depth":1,"next":{"title":"GitBook is nice","level":"1.3","depth":1,"path":"part1/gitbook.md","ref":"part1/gitbook.md","articles":[]},"previous":{"title":"Introduction","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-sharing","splitter","expandable-chapters-small","anchors","github","github-buttons","donate","sharing-plus","anchor-navigation-ex","favicon"],"styles":{"website":"./styles/website.css"},"pluginsConfig":{"github":{"url":"https://github.com/Blankj"},"splitter":{},"search":{},"sharing-plus":{"qq":false,"all":["facebook","google","twitter","instapaper","linkedin","pocket","stumbleupon"],"douban":false,"facebook":true,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":true,"messenger":false,"line":false,"vk":false,"pocket":true,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"./source/images/donate.png","alipayText":" ","button":"赞赏","title":"","wechat":"","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"highlight":{},"anchor-navigation-ex":{"associatedWithSummary":true,"float":{"floatIcon":"fa fa-navicon","level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"mode":"float","multipleH1":true,"pageTop":{"level1Icon":"","level2Icon":"","level3Icon":"","showLevelIcon":false},"printLog":false,"showGoTop":true,"showLevel":false},"favicon":{"shortcut":"./source/images/favicon.jpg","bookmark":"./source/images/favicon.jpg","appleTouch":"./source/images/apple-touch-icon.jpg","appleTouchMore":{"120x120":"./source/images/apple-touch-icon.jpg","180x180":"./source/images/apple-touch-icon.jpg"}},"github-buttons":{"buttons":[{"user":"Blankj","repo":"glory","type":"star","size":"small","count":true}]},"expandable-chapters-small":{},"sharing":{"qq":false,"all":["google","facebook","weibo","twitter","qq","qzone","linkedin","pocket"],"douban":false,"facebook":false,"weibo":false,"instapaper":false,"whatsapp":false,"hatenaBookmark":false,"twitter":false,"messenger":false,"line":false,"vk":false,"pocket":false,"google":false,"viber":false,"stumbleupon":false,"qzone":false,"linkedin":false},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"anchors":{}},"theme":"default","author":"gugu","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"react源码详细解读","language":"zh-hans","links":{"sidebar":{"我的狗窝":"https://blankj.com"}},"gitbook":"3.2.3","description":"select * from learn"},"file":{"path":"part1/writing.md","mtime":"2018-11-08T02:50:54.354Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-11-08T02:54:21.626Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-expandable-chapters-small/expandable-chapters-small.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-github-buttons/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing-plus/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

